package com.kotlin.hxh.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.kotlin.hxh.ui.fragment.second.child.childpager.FirstPagerFragment
import com.kotlin.hxh.ui.fragment.second.child.childpager.OtherPagerFragment

/**
 * @author huxh
 * @date 2018/12/20.
 */
class ZhihuPagerFragmentAdapter(fm: androidx.fragment.app.FragmentManager, vararg titles: String) : androidx.fragment.app.FragmentPagerAdapter(fm) {
    private val mTitles: Array<out String>

    init {
        mTitles = titles
    }

    override fun getItem(p0: Int): androidx.fragment.app.Fragment {
        if (p0 == 0) {
            return FirstPagerFragment.newInstance()
        } else {
            return OtherPagerFragment.newInstance(mTitles[p0])
        }
    }

    override fun getCount() = mTitles.size

    override fun getPageTitle(position: Int) = mTitles[position]
}

